const notice_model = require('../db/notice_model')

// 获取前8条公告
const get_notice_top8 = async (ctx) => {
    try {
      const notices = await notice_model.notice_select_top8()
      // console.log('----')
      // console.log(notices)
      ctx.body = notices
    } catch (error) {
      ctx.throw(400, error)
    }
  }

const get_notice_all = async (ctx) => {
    try {
      const notices = await notice_model.notice_all_select()
      ctx.body = notices
    } catch (error) {
      ctx.throw(400, error)
    }
  }

const get_notice = async (ctx, next) => {
    const {id} = ctx.params
    try {
      const notice = await notice_model.notice_select_by_id(id)
      ctx.body = notice
    } catch (error) {
      ctx.throw(400, error)
    }
  }
// 新增
const insted_notice = async (ctx) => {
  const noticed = {notice_title,notice_content,_name,Release_date,serial_number} = ctx.request.body
  try {
    const result = await notice_model.notice_insert_inst(noticed)
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}

// notice_delete_by_id
const delete_notice =  async (ctx) => {
  const {id} = ctx.request.body
  try {
    const norices = await notice_model.notice_delete_by_id(id)
    ctx.body = norices
  } catch (error) {
    ctx.throw(400, error)
  }
}


module.exports = {
    get_notice_top8,
    get_notice_all,
    get_notice,
    insted_notice,
    delete_notice
  }
